<?php
if($_POST['order_ids']){
    $order_ids = trim($_POST['order_ids']);
    $replaceStr = (strpos($order_ids,',') != false) ? '' : ',';
    $order_ids = preg_replace('/\r\n/', $replaceStr, $order_ids);
    $orderIds = explode(',', $order_ids);
    if(!empty($orderIds)){
        include_once("../module/micro_shop/includes/plugin_micro_shop_class.php");
        $microShop = new MicroShop();
        
        foreach ($orderIds as $orderId_temp){
            if(strpos($orderId_temp, '_') != false){
                $temp = explode('_', $orderId_temp);
                $orderId = $temp[0];
                $cost = $temp[1];
            }else{
                $orderId = $orderId_temp;
                $cost = 0;
            }
            
            if($_POST['submit']=='GIVE'){
                if ($cost>0) {
                    $microShop->giveOutBonusOfOrder($orderId,true,$cost);
                } else {
                    $microShop->giveOutBonusOfOrder($orderId,true);
                }
            }
            if($_POST['submit1']=='CONFIRM'){
                $microShop->updateBonusAfterFinishOrder($orderId);
            }
        }
    }
}
$tpl->display("give_shop_bonus.htm");